package disanzhou;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;


abstract class Shape implements Comparable<Shape>{
	public abstract double getArea();
	public int compareTo(Shape o) {
		return (int) (this.getArea()- o.getArea());
	}
	public static double sumAllArea(Shape[] shapes) {
		double sumAllArea = 0;

		for (Shape shape : shapes) {
			sumAllArea += shape.getArea();
		}

		return sumAllArea;
	}

	public static void main(String[] args) {
		ArrayList<Shape> arr = new ArrayList<Shape>();
		Shape[] S = new Shape[6];
//		arr.add(new Rectangle(1, 2));
//		arr.add(new Rectangle(3, 6));
//		arr.add(new Circle(2));
//		arr.add(new Circle(4));
//		Circle str1 = new Circle(2);
//		Circle str2 = new Circle(2);
//		System.out.println(str1.equals(str2));
		S[0] = new Rectangle(4, 2);
		S[1] = new Rectangle(5, 6);
		S[2] = new Rectangle(3, 6);
		S[3] = new Circle(1);
		S[4] = new Circle(5);
		S[5] = new Circle(3);
		Arrays.sort(S);
		for (Shape shape : S) {
			System.out.println(shape.toString());
			System.out.println(shape.getArea());
		}
		
		
		//System.out.println(Shape.sumAllArea((Shape[]) arr.toArray(S)));
		// TODO Auto-generated method stub

	}

}

class Circle extends Shape {
	private int radius;

	public Circle(int radius) {
		this.radius = radius;
	}

	public double getArea() {
		return radius * radius * Math.PI;
	}


	@Override
	public String toString() {
		return "Circle [radius=" + radius + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + radius;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Circle other = (Circle) obj;
		if (radius != other.radius)
			return false;
		return true;
	}

	

//	public int compareTo(Shape o) {
//		// TODO Auto-generated method stub
//		return (int) (this.getArea()- o.getArea());
//	}
	
}

class Rectangle extends Shape {
	private int width;
	private int length;

	public Rectangle(int width, int length) {
		this.width = width;
		this.length = length;
	}

	public double getArea() {
		return width * length;
	}

	@Override
	public String toString() {
		return "Rectangle [width=" + width + ", length=" + length + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + length;
		result = prime * result + width;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Rectangle other = (Rectangle) obj;
		if (length != other.length)
			return false;
		if (width != other.width)
			return false;
		return true;
	}

//	public int compareTo(Shape o) {
//		// TODO Auto-generated method stub
//		return (int) (this.getArea()- o.getArea());
//	}
}
